package cn.edu.hy.demo05.controller;

import cn.edu.hy.demo05.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

@Controller
@RequestMapping("/customer")
public class CustomerController {

//    @GetMapping("/test.do")
    @RequestMapping(value = {"","test.do","test1.do"})
    public ModelAndView test(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("username","张三");

        modelAndView.setViewName("demo05/test");
        return  modelAndView;
    }


    @GetMapping("login")
    public ModelAndView getLogin(){

        return new ModelAndView("demo05/userLogin");
    }


    @PostMapping("login")
    public ModelAndView postLogin(String userName, String passWord, @RequestParam ArrayList<String> hobby  , User user, ModelMap modelMap){

        modelMap.put("user1",userName);
        modelMap.put("pwd",passWord);
        modelMap.put("user",user);


        for (int i = 0; i < hobby.size(); i++) {
            System.out.println(hobby.get(i));
        }


        return new ModelAndView("demo05/test",modelMap);
    }

}
